<%@ page language="java" isThreadSafe="true" %>
<%@ page import="java.util.Hashtable,
                 ro.gateway.aida.servlet.EditLocationServlet,
                 ro.gateway.aida.obj.Country,
                 ro.gateway.aida.obj.Region,
                 ro.gateway.aida.srv.EditorServlet,
                 ro.gateway.aida.obj.County,
                 ro.gateway.aida.obj.Town,
                 ro.gateway.aida.obj.Village
                 "%>
<%@ taglib uri="/WEB-INF/translator.tld" prefix="loc_edit" %>     
<!--Imports from request-->
<% 

Hashtable bean=EditLocationServlet.getBean(request);

Country []countrylist=(Country[])bean.get("countrylist");
String countrysel=(String)bean.get("countrysel");

String regionsel=(String)bean.get("regionsel");
Region [] regionlist=(Region[])bean.get("regionlist");

String countysel=(String)bean.get("countysel");
County [] countylist=(County[])bean.get("countylist");

String townsel=(String)bean.get("townsel");
Town [] townlist=(Town[])bean.get("townlist");

String villagesel=(String)bean.get("villagesel");
Village [] villagelist=(Village[])bean.get("villagelist");


String editing_action = (String) bean.get(EditorServlet.PNAME_ACTION);
String key = (String) bean.get(EditorServlet.PNAME_KEY);
String ctx = request.getContextPath();
String error=(String)bean.get("error");
EditorServlet.beanSync(bean,"error",null);

String selected="";

%>
            
            
<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>Edit Location Information </title>
<link rel="stylesheet" href="../alf.css" type="text/css">
</head>
<body bgcolor="#FFFFFF"><p>
<div align=center class=text_bold>Location Editor</div>
<blockquote class="text_search">

<% if (error!=null) {%>
<font color=red>
<p><b>An error occured in <%=error%>.</b>
</font>
<p>
<% } %>

<form name="lform" method=post action="<%=ctx%>/loc/edit">

<!--Javascript-->
<script language="javascript">
function lsubmit(action,param) {
	lform.action.value=action;
	lform.param.value=param;
	lform.submit();
}
</script>
<!--/Javascript-->

<!--Hidden fields-->
	<input type="hidden" name="<%=EditorServlet.PNAME_KEY%>" value="<%=key%>" />
	<input type="hidden" name="<%=EditorServlet.PNAME_ACTION%>" value="<%=EditorServlet.PV_ACTION_EDIT%>" />
	<input type="hidden" name="param" value="" />
<!--/Hidden fields-->

<!--Country select-->
Country:<select style="BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #999999 1px solid; BORDER-LEFT: #999999 1px solid; BORDER-RIGHT: #999999 1px solid; BORDER-TOP: #999999 1px solid; FONT: 11px Verdana, Arial, san-serif;" name="countrylist" onchange="javascript:lsubmit('<%=EditorServlet.PV_ACTION_EDIT%>','countrysel');">
<option value="">--Select--</option>
<% 
selected="";
for (int i = 0; i < countrylist.length; i++,selected="") {
	if(countrylist[i].getIso3().equals(countrysel)) selected="selected";
	%><option value="<%=countrylist[i].getIso3()%>" <%=selected%>><%=countrylist[i].getName()%></option><%
}
%>
</select>

<!--Region select and insert section-->
<%if(countrysel!=null) {%>
<p>
<%if(regionlist!=null) { %>
Region:<select name="regionlist" onchange="javascript:lsubmit('<%=EditorServlet.PV_ACTION_EDIT%>','regionsel');">
<option value="">--Select--</option>
<% 
selected="";

for (int i = 0; i < regionlist.length; i++,selected="") {
	if(Integer.toString(regionlist[i].getId()).equals(regionsel)) selected="selected";
	%><option value="<%=regionlist[i].getId()%>" <%=selected%>><%=regionlist[i].getName()%></option><%
}
%>
</select>
<input name="deleteregionbutton" type="button" value="Delete Region" onclick="javascript:lsubmit('<%=EditorServlet.PV_ACTION_SAVE%>','delregion');" class="buton">
<%}%>
<input style="BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #999999 1px solid; BORDER-LEFT: #999999 1px solid; BORDER-RIGHT: #999999 1px solid; BORDER-TOP: #999999 1px solid; FONT: 11px Verdana, Arial, san-serif;" type=text name="newregion" maxlength="128"/>
<input name="newregionbutton" type="button" value="New Region" onclick="javascript:lsubmit('<%=EditorServlet.PV_ACTION_SAVE%>','newregion');" class="buton">

<%}%>

<!--County select and insert section-->
<%if(regionsel!=null) {%>
<p>
<%if(countylist!=null) { %>
County:<select name="countylist" onchange="javascript:lsubmit('<%=EditorServlet.PV_ACTION_EDIT%>','countysel');">
<option value="">--Select--</option>
<% 
selected="";

for (int i = 0; i < countylist.length; i++,selected="") {
	if(Integer.toString(countylist[i].getId()).equals(countysel)) selected="selected";
	%><option value="<%=countylist[i].getId()%>" <%=selected%>><%=countylist[i].getName()%></option><%
}
%>
</select>
<input name="deletecountybutton" type="button" value="Delete County" onclick="javascript:lsubmit('<%=EditorServlet.PV_ACTION_SAVE%>','delcounty');" class="buton">
<%}%>
<input style="BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #999999 1px solid; BORDER-LEFT: #999999 1px solid; BORDER-RIGHT: #999999 1px solid; BORDER-TOP: #999999 1px solid; FONT: 11px Verdana, Arial, san-serif;" type=text name="newcounty" maxlength="128"/>
<input name="newcountybutton" type="button" value="New County" onclick="javascript:lsubmit('<%=EditorServlet.PV_ACTION_SAVE%>','newcounty');" class="buton">

<%}%>

<!--Town select and insert section-->
<%if(countysel!=null) {%>
    <p> 
      <%if(townlist!=null) { %>
      Town:
      <select name="townlist"  onchange="javascript:lsubmit('<%=EditorServlet.PV_ACTION_EDIT%>','townsel');">
        <option value="">--Select--</option>
        <% 
selected="";
String csirsup="";
for (int i = 0; i < townlist.length; i++,selected="") {
	if(Integer.toString(townlist[i].getSirsup_id()).equals(townsel)) {selected="selected";csirsup=Integer.toString(townlist[i].getSirsup_id());}
	%>
        <option value="<%=townlist[i].getSirsup_id()%>" <%=selected%>><%=townlist[i].getName()%></option>
        <%
}
%>
      </select>
      SIRSUP <%=csirsup%> 
      <input name="deletetownbutton" type="button" value="Delete Town" onclick="javascript:lsubmit('<%=EditorServlet.PV_ACTION_SAVE%>','deltown');" class="buton">
      <%}%>
      <br>
      <span class="text_searchbold">Add a new town: </span><span class="text_search">Name</span>: 
      <input style="BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #999999 1px solid; BORDER-LEFT: #999999 1px solid; BORDER-RIGHT: #999999 1px solid; BORDER-TOP: #999999 1px solid; FONT: 11px Verdana, Arial, san-serif;" type=text name="newtownname" maxlength="128"/>
      SIRSUP ID:
      <input style="BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #999999 1px solid; BORDER-LEFT: #999999 1px solid; BORDER-RIGHT: #999999 1px solid; BORDER-TOP: #999999 1px solid; FONT: 11px Verdana, Arial, san-serif;" type=text name="newtownsirsupid" maxlength="7"/>
      Type:
      <select name="newtowntype">
        <option value="1">Municipality</option>
        <option value="2">City</option>
        <option value="3">Town</option>
      </select>
      <input name="newtownbutton" type="button" value="New Town" onclick="javascript:lsubmit('<%=EditorServlet.PV_ACTION_SAVE%>','newtown');" class="buton">
      <%}%>
      <!--Village select and insert section-->
      <%if(townsel!=null) {%>
    <p> 
      <%if(villagelist!=null) { %>
      Village: 
      <select name="villagelist" onchange="javascript:lsubmit('<%=EditorServlet.PV_ACTION_EDIT%>','villagesel');">
        <option value="">--Select--</option>
        <% 
selected="";
String csiruta="";
for (int i = 0; i < villagelist.length; i++,selected="") {
	if(Integer.toString(villagelist[i].getSiruta_id()).equals(villagesel)) {selected="selected";csiruta=Integer.toString(villagelist[i].getSiruta_id());}
	%>
        <option value="<%=villagelist[i].getSiruta_id()%>" <%=selected%>><%=villagelist[i].getName()%></option>
        <%
}
%>
      </select>
      SIRUTA <%=csiruta%> 
      <input name="deletevillagebutton" type="button" value="Delete Village" onclick="javascript:lsubmit('<%=EditorServlet.PV_ACTION_SAVE%>','delvillage');" class="buton">
      <%}%>
      <br>
      <span class="text_searchbold">Add a new village: &nbsp;</span>Name: 
      <input style="BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #999999 1px solid; BORDER-LEFT: #999999 1px solid; BORDER-RIGHT: #999999 1px solid; BORDER-TOP: #999999 1px solid; FONT: 11px Verdana, Arial, san-serif;" type=text name="newvillagename" maxlength="128"/>
      SIRUTA ID: 
      <input style="BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: #999999 1px solid; BORDER-LEFT: #999999 1px solid; BORDER-RIGHT: #999999 1px solid; BORDER-TOP: #999999 1px solid; FONT: 11px Verdana, Arial, san-serif;" type=text name="newvillagesirutaid" maxlength="7"/>
      <input name="newvillagebutton" type="button" value="New Village" onclick="javascript:lsubmit('<%=EditorServlet.PV_ACTION_SAVE%>','newvillage');" class="buton">
      <%}%>
  </form>

</blockquote>

</body>
</html>